<?php

namespace LEA\StageBundle\Controller;
use LEA\UserBundle\Utility\Auth;
use LEA\StageBundle\Utility\Utility;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use LEA\StageBundle\SQL\queries;
use LEA\StageBundle\Form\ListeSituationEtudiant;
use LEA\StageBundle\Form\ListeFormation;
use LEA\StageBundle\Form\ListeTuteur;

class ProfChoixEtudController extends Controller
{
    public function indexAction($user, $refYear)
    {
    	$auth = new Auth();
    	$conn = $this->container->get('database_connection');

    	$request = $this->getRequest();

        if ($request->getMethod() == 'POST') {
            $form->bind($request);

            if ($form->isValid()) {
            }
        }

    	$array = $this->responsableArray($conn, $user, $refYear, $request=$this->getRequest(), $auth) ;
		return $this->render('LEAStageBundle:ProfChoixEtud:index.html.php', $array) ;
    }

    private function responsableArray($conn, $user, $refYear, $request, $auth){
			if($auth->hasRole($request, 'PROF_ROLE')){
    		$arrayProf = array("Mes étudiants","Mes choix","Choisir étudiants","Rapport &amp; Soutenance");
    		$menuProf=array("lea_dumb_route","lea_dumb_route","lea_prof_choix_etud","lea_dumb_route","lea_dumb_route");
		}
    	$arraySecr =null;
    	if($auth->hasRole($request, 'SECR_ROLE')){
			$arraySecr = array("Etudiants par formation", "Etudiants par entreprise", "Etudiants par tuteur","Referents par entreprise"," Gestion des Bureaux") ;
			$menuSecr=array("lea_dumb_route","lea_dumb_route","lea_dumb_route","lea_dumb_route","lea_dumb_route");
		}
		$arrayResp = null;
		if($auth->hasRole($request, 'RESP')){
			$arrayResp = array("Encadrement par étud.","par tuteur","Actions","Attribution","Rapport &amp; Soutenance","Stats","Inscrire Etud","Admin");
			$menuResp=array("lea_dumb_route","lea_dumb_route","lea_resp_action","lea_dumb_route","lea_dumb_route","lea_dumb_route","lea_dumb_route","lea_dumb_route");
		}
			$form = $this->createForm(new ListeSituationEtudiant) ;
			$listeSituationEtu = $form->createView();

			$form = $this->createForm(new ListeFormation) ;
			$listeFormation = $form->createView();

		//	$form = $this->createForm(new ListeTuteur, array('conn' => $conn, 'session' => $request->getSession()) ) ;
		//	$listeTuteur = $form->createView();

			$session = $request->getSession();
  			$queries = new Queries($conn, $session);
			$listeEtud=$queries->doQueryListEtudiantsParFormation("L3INFOFI", false);

			//$tuteurs = doQueryTuteursPotentiels($formation, $row[0]);

			return array('user' => $user,
						 'refYear' => $refYear,
						 'arrayProf' => $arrayProf,
						 'arraySecr' => $arraySecr,
						 'arrayResp' => $arrayResp,
						 'menuProf' => $menuProf,
					 	 'menuSecr' => $menuSecr,
					 	 'menuResp' => $menuResp,
						 'listeSituationEtu' => $listeSituationEtu,
						 'listeFormation' => $listeFormation,
						 'listeEtud' => $listeEtud
					);
    	}
}
